package com.eagle.security.entries;

import java.util.HashMap;

import org.apache.commons.lang.StringUtils;

public class UserExtendInfo extends HashMap<String, Object>
{
    private static final long serialVersionUID = 6688392813133524826L;

    public String getString(String key)
    {
        return getString(key, null);
    }

    public String getString(String key, String defValue)
    {
        Object value = get(key);
        return value instanceof String ? (String) value : defValue;
    }

    public Boolean getBoolean(String key)
    {
        return getBoolean(key, null);
    }

    public Boolean getBoolean(String key, Boolean defValue)
    {
        Object value = get(key);
        return value instanceof Boolean ? (Boolean) value : defValue;
    }

    public Integer getInteger(String key)
    {
        return getInteger(key, null);
    }

    public Integer getInteger(String key, Integer defValue)
    {
        Object value = get(key);
        return value instanceof Integer ? (Integer) value : defValue;
    }

    public Long getLong(String key)
    {
        return getLong(key, null);
    }

    public Long getLong(String key, Long defValue)
    {
        Object value = get(key);
        return (value instanceof Long || value instanceof Integer) ? (Long) value : defValue;
    }

    public Object put(String key, Object value)
    {
        if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
        {
            return super.remove(key);
        }
        else
        {
            return super.put(key, value);
        }
    }
}
